package ejb.entities;

import java.io.Serializable;

import javax.persistence.*;

import ejb.dto.ProdottoBaseDTO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the basicproducts database table.
 * 
 */
@Entity
@Table(name = "basicproducts")
@NamedQueries({
		@NamedQuery(name = "Basicproduct.findAll", query = "SELECT b FROM Basicproduct b"),
		@NamedQuery(name = "Basicproduct.findByID", query = "SELECT b FROM Basicproduct b WHERE b.basicproductid LIKE :id")})
public class Basicproduct implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_ALL = "Basicproduct.findAll";
	public static final String FIND_BYID = "Basicproduct.findByID";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int basicproductid;

	@Temporal(TemporalType.DATE)
	private Date enddate;

	@Temporal(TemporalType.DATE)
	private Date startdate;

	private float price;

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	private int places;

	// bi-directional many-to-many association to Giftlist
	@ManyToMany
	@JoinTable(name = "giftlist_basicproduct", joinColumns = { @JoinColumn(name = "basicproductid") }, inverseJoinColumns = { @JoinColumn(name = "giftlistid") })
	private List<Giftlist> giftlists;

	// bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name = "userid")
	private User user;

	// bi-directional one-to-one association to Escursion
	@OneToOne(mappedBy = "basicproduct", cascade = { CascadeType.ALL })
	private Escursion escursion;

	// bi-directional one-to-one association to Flight
	@OneToOne(mappedBy = "basicproduct", cascade = { CascadeType.ALL })
	private Flight flight;

	// bi-directional one-to-one association to Hotel
	@OneToOne(mappedBy = "basicproduct", cascade = { CascadeType.ALL })
	private Hotel hotel;

	// bi-directional many-to-one association to UserBasicproduct
	@OneToMany(mappedBy = "basicproduct")
	private List<UserBasicproduct> userBasicproducts;

	// bi-directional many-to-many association to Pack
	@ManyToMany(mappedBy = "basicproducts" , cascade = { CascadeType.ALL } )
	private List<Pack> packs;

	public Basicproduct() {
	}

	public Basicproduct(ProdottoBaseDTO pBaseDTO) {
		this.startdate = pBaseDTO.getDataInizio();
		this.enddate = pBaseDTO.getDataFine();
		this.price = pBaseDTO.getPrezzo();
		this.places = pBaseDTO.getNposti();
	}

	public int getBasicproductid() {
		return this.basicproductid;
	}

	public void setBasicproductid(int basicproductid) {
		this.basicproductid = basicproductid;
	}

	public Date getEnddate() {
		return this.enddate;
	}

	public void setEnddate(Date enddate) {
		this.enddate = enddate;
	}

	public Date getStartdate() {
		return this.startdate;
	}

	public void setStartdate(Date startdate) {
		this.startdate = startdate;
	}

	public int getPlaces() {
		return places;
	}

	public void setPlaces(int places) {
		this.places = places;
	}

	public List<Giftlist> getGiftlists() {
		return this.giftlists;
	}

	public void setGiftlists(List<Giftlist> giftlists) {
		this.giftlists = giftlists;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Escursion getEscursion() {
		return this.escursion;
	}

	public void setEscursion(Escursion escursion) {
		this.escursion = escursion;
	}

	public Flight getFlight() {
		return this.flight;
	}

	public void setFlight(Flight flight) {
		this.flight = flight;
	}

	public Hotel getHotel() {
		return this.hotel;
	}

	public void setHotel(Hotel hotel) {
		this.hotel = hotel;
	}

	public List<UserBasicproduct> getUserBasicproducts() {
		return this.userBasicproducts;
	}

	public void setUserBasicproducts(List<UserBasicproduct> userBasicproducts) {
		this.userBasicproducts = userBasicproducts;
	}

	public UserBasicproduct addUserBasicproduct(
			UserBasicproduct userBasicproduct) {
		getUserBasicproducts().add(userBasicproduct);
		userBasicproduct.setBasicproduct(this);

		return userBasicproduct;
	}

	public UserBasicproduct removeUserBasicproduct( UserBasicproduct userBasicproduct) 
	{
		getUserBasicproducts().remove(userBasicproduct);
		userBasicproduct.setBasicproduct(null);

		return userBasicproduct;
	}

	public List<Pack> getPacks() {
		return this.packs;
	}

	public void setPacks( Pack pack ) 
	{
		if( this.packs == null )
			packs = new ArrayList<Pack>();
		this.packs.add(pack);
	}

	public Pack removePack(Pack pack) {
		getPacks().remove(pack);
		return pack;
	}
}